import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({

    state: {
        // 视频
        videoUrl: window.localStorage.getItem('videoUrl') ?? '',
        // 粉丝
        mid: window.localStorage.getItem('mid') ?? '',
        // name
        userName: '',
        // 直播
        uid: window.localStorage.getItem('uid') ?? '',
        // 是否静音(全局)
        isMute: JSON.parse(window.localStorage.getItem('isMute')) ?? false,
        // 全局音量大小
        GlobalAudioValue: +window.localStorage.getItem('GlobalAudioValue') ?? 1,
        // 人气
        Popularity: 0,
        // 全局透明度
        transparency: 99,
        // 是否清除入场信息
        interMessage: JSON.parse(window.localStorage.getItem('interMessage')) ?? false,
        // 点歌歌单
        songList: JSON.parse(window.localStorage.getItem('songList')) ?? [],
        // 全局
        GlobalAudio: JSON.parse(window.localStorage.getItem('GlobalAudio')) ?? true,
        // 进场
        intoAudio: JSON.parse(window.localStorage.getItem('intoAudio')) ?? true,
        // 弹幕
        BarrageAudio: JSON.parse(window.localStorage.getItem('BarrageAudio')) ?? true,
        // 礼物
        giftAudio: JSON.parse(window.localStorage.getItem('giftAudio')) ?? true,
        // 音乐
        songAudio: JSON.parse(window.localStorage.getItem('songAudio')) ?? true
    },

    mutations: {
        changevideoUrl(state, payload) {
            state.videoUrl = payload
        },
        changemid(state, payload) {
            state.mid = payload
        },
        changeuserName(state, payload) {
            state.userName = payload
        },
        changeuid(state, payload) {
            state.uid = payload
        },
        changeIsMute(state, payload) {
            state.isMute = payload
        },
        changePopularity(state, payload) {
            state.Popularity = payload
        },
        changetransparency(state, payload) {
            state.transparency = payload
        },
        changeinterMessage(state, payload) {
            state.interMessage = payload
        },
        changeSongList(state, payload) {
            state.songList = payload
        },
        changeSongListPush(state) {
            state.songList.splice(0, 1)
        },
        changeGlobalAudio(state, payload) {
            state.GlobalAudio = payload
        },
        changeGlobalAudioValue(state, payload) {
            state.GlobalAudioValue = +payload
        },
        changeintoAudio(state, payload) {
            state.intoAudio = payload
        },
        changeBarrageAudio(state, payload) {
            state.BarrageAudio = payload
        },
        changegiftAudio(state, payload) {
            state.giftAudio = payload
        },
        changesongAudio(state, payload) {
            state.songAudio = payload
        }
    },
    actions: {
        videoUrl({
            commit
        }, payload) {
            commit('changevideoUrl', payload)
        },
        mid({
            commit
        }, payload) {
            commit('changemid', payload)
        },
        userName({
            commit
        }, payload) {
            commit('changeuserName', payload)
        },
        uid({
            commit
        }, payload) {
            commit('changeuid', payload)
        },
        Popularity({
            commit
        }, payload) {
            commit('changePopularity', payload)
        }
    }

})
export default store